package com.apping.module.button;

import com.apping.module.R;
import com.umeng.analytics.MobclickAgent;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class ButtonClickEventAtv extends Activity implements OnClickListener,
		OnTouchListener, OnKeyListener, OnFocusChangeListener {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.apping_button_click);

		Button button1 = (Button) findViewById(R.id.button1);
		Button button2 = (Button) findViewById(R.id.button2);
		Button button3 = (Button) findViewById(R.id.button3);
		Button button4 = (Button) findViewById(R.id.button4);

		button1.setOnClickListener(this);
		button2.setOnTouchListener(this);
		button3.setOnFocusChangeListener(this);
		button4.setOnKeyListener(this);
	}

	public void onResume() {
		super.onResume();
		MobclickAgent.onPageStart("SplashScreen"); // 统计页面
		MobclickAgent.onResume(this); // 统计时长
	}

	public void onPause() {
		super.onPause();
		MobclickAgent.onPageEnd("SplashScreen"); // 保证 onPageEnd 在onPause
													// 之前调用,因为 onPause 中会保存信息
		MobclickAgent.onPause(this);
	}

	@Override
	public void onClick(View v) {
		Button onClickButton = (Button) findViewById(R.id.button1);
		onClickButton.setText("on click");
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		Button onTouchButton = (Button) v;
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			onTouchButton.setText("on touch down");
		}

		if (event.getAction() == MotionEvent.ACTION_UP) {
			onTouchButton.setText("on touch up");
		}
		return false;
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		Button focusButton = (Button) v;
		if (hasFocus) {
			focusButton.setText("focus on");
		} else {
			focusButton.setText("focus not on");
		}

	}

	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		Button onKeyButton = (Button) v;
		if (KeyEvent.ACTION_DOWN == event.getAction()) {
			onKeyButton.setText("key down");
		} else if (KeyEvent.ACTION_UP == event.getAction()) {
			onKeyButton.setText("key up");
		}
		return false;
	}
}